package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Hotel;
import cn.wolfcode.trip.base.domain.HotelDetail;
import cn.wolfcode.trip.base.mapper.HotelDetailMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class HotelDetailServiceImpl implements IHotelDetailService {
    @Autowired
    private HotelDetailMapper hotelDetailMapper;

    @Override
    public void saveOrUpdate(HotelDetail hotelDetail) {
        if (hotelDetail.getId()!=null) {
            hotelDetailMapper.updateByPrimaryKey(hotelDetail);
        }else{
            hotelDetailMapper.insert(hotelDetail);
        }
    }

    @Override
    public void delete(Long id) {
       hotelDetailMapper.deleteByPrimaryKey(id);
    }

    @Override
    public HotelDetail selectByPrimaryKey(Long id) {
        return hotelDetailMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HotelDetail> selectAll() {
        return hotelDetailMapper.selectAll();
    }

    @Override
    public List<HotelDetail> listByHotelId(Long id) {
        return hotelDetailMapper.selectByHotelId(id);
    }

    @Override
    public PageInfo<HotelDetail> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<HotelDetail> list = hotelDetailMapper.queryForList(qo);
        return new PageInfo<>(list);
    }
}
